package com.xkh.rocketmq.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RocketMQConsumer {

    @EventListener(condition = "#event.msg[0].topic=='Topic-1' && #event.msg[0].tags=='test1'")
    public void test1(RocketMQEvent event) {
        MessageExt ext = event.getMsg().get(0);
        log.info("内容:"+new String(ext.getBody()));
        log.info("消息ID:"+ext.getKeys());

    }

    @EventListener(condition = "#event.msg[0].topic=='Topic-2' && #event.msg[0].tags=='test2'")
    public void test2(RocketMQEvent event) {
        MessageExt ext = event.getMsg().get(0);
        log.info("内容:"+new String(ext.getBody()));
        log.info("消息ID:"+ext.getKeys());
    }

    @EventListener(condition = "#event.msg[0].topic=='Topic-3' && #event.msg[0].tags=='test3'")
    public void test3(RocketMQEvent event) {
        MessageExt ext = event.getMsg().get(0);
        log.info("消息ID:"+ext.getKeys()+" 内容:"+new String(ext.getBody()));
    }
}
